package com.demo.my.Controller.detail;

import com.demo.my.Entity.Employee;
import com.demo.my.Service.EmployeeService;
import com.mysql.jdbc.StringUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/oneselfDetail")
public class detailServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String vid = req.getParameter("vid");
        if(StringUtils.isNullOrEmpty(vid)){
            resp.setContentType("text/html;charset=utf-8");
            resp.getWriter().write("<script type=\"text/javascript\">\n" +
                    "\talert(\"查询个人信息有误，请重新登录\")\n" +
                    "\tsetTimeout(function () {\n" +
                    "\t\twindow.location.href = \"/jsp/login.jsp\";\n" +
                    "    },1000)\n" +
                    "</script>");
            return;
        }
         Integer id = Integer.parseInt(vid);
        //获得id 查询Employee 的信息

        Employee infoById = null;
        try {
            infoById = EmployeeService.getInfoById(id);
        } catch (Exception e) {
            System.out.println("employee个人信息为空");
        }
        req.setAttribute("employee",infoById);
        req.getRequestDispatcher("/jsp/admin/oneself_detail.jsp").forward(req,resp);
        //jsp/admin/oneself_detail.jsp


    }
}
